package com.lc.zpyh.ui.activity.mine;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.widget.view.ClearEditText;
import com.lc.zpyh.R;
import com.lc.zpyh.app.AppActivity;
import com.lc.zpyh.http.request.TheInvitationCodeApi;
import com.lc.zpyh.http.response.TheInvitationCodeBean;
import com.lc.zpyh.other.IntentKey;

import androidx.appcompat.widget.AppCompatButton;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class InvitationCodeActivity extends AppActivity {
    @BindView(R.id.et_Invitation_code)
    EditText etInvitationCode;
    @BindView(R.id.btn_phone_reset_commit)
    AppCompatButton btnPhoneResetCommit;
    @BindView(R.id.title_bar_top)
    TitleBar titleBarTop;
    @BindView(R.id.et_password)
    ClearEditText etPassword;
    @BindView(R.id.et_password_agine)
    ClearEditText etPasswordAgine;
    private String userId;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_invitationcode;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        userId = getIntent().getStringExtra(IntentKey.USERID);
        Log.e("TAG", "onCreate: " + userId);
        titleBarTop.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {

            }

            @Override
            public void onRightClick(View v) {
                finish();
            }
        });
    }

    @OnClick(R.id.btn_phone_reset_commit)
    public void onClick() {
        if (etPassword.getText().toString().isEmpty()) {

            toast(R.string.common_password_input_error);
            return;
        }
        if (etPasswordAgine.getText().toString().isEmpty()) {

            toast(R.string.common_password_input_error);
            return;
        }
        if (!etPassword.getText().toString().trim().equals(etPasswordAgine.getText().toString().trim())){
            toast(R.string.common_password_input_unlike);
            return;
        }
//网络请求
        EasyHttp.post(this)
                .api(new TheInvitationCodeApi()
                        .setUserId(userId).setInvitationCode(etInvitationCode.getText().toString()).setPassWord(etPassword.getText().toString().trim())).request(new HttpCallback<TheInvitationCodeBean>(this) {

            @Override
            public void onSucceed(TheInvitationCodeBean data) {
                if (data.getCode() == 0) {
                    toast("登录成功");

                    // 隐藏软键盘
                    hideKeyboard(getCurrentFocus());
                    finish();

                } else {
                    toast(data.getList());

                }


            }

            @Override
            public void onFail(Exception e) {
                super.onFail(e);

            }
        });

    }
}
